/**
 * Copyright © 2016 公司名. All rights reserved.
 * 
 * @Title: BuyserServiceImpl.java
 * @Prject: LianniuWeb
 * @Package: com.lianniu.web.buyerProduct.service.impl
 * @Description: TODO
 * @author: lzz
 * @date: 2016年9月2日 上午9:50:36
 * @version: V1.0
 */
package com.lianniu.web.buyerProduct.service.impl;

import com.lianniu.web.base.BaseResult;
import com.lianniu.web.buyerProduct.dao.IBuyerInfoDao;
import com.lianniu.web.buyerProduct.model.BuyerConsigneeVo;
import com.lianniu.web.buyerProduct.model.BuyerInfoVo;
import com.lianniu.web.buyerProduct.service.IBuyerInfoService;
import com.lianniu.web.constants.ErrorCode;
import com.lianniu.web.util.StringUtil;
import com.lianniu.web.util.UUIDUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @ClassName: BuyserServiceImpl
 * @author: lzz
 * @date: 2016年9月2日 上午9:50:36
 */
@Service("buyserInfoService")
public class BuyserInfoServiceImpl implements IBuyerInfoService {
    public static final Logger LOGGER = Logger.getLogger(BuyserInfoServiceImpl.class);

    @Autowired
    private IBuyerInfoDao buyerInfoDao;

    @Override
    public BaseResult getBuyerInfoByUserId(String userId) {
        LOGGER.info("BuyserServiceImpl getBuyerInfoByUserId begin");
        BuyerInfoVo buyerInfo = buyerInfoDao.getBuyerInfoByUserId(userId);
        LOGGER.info("BuyserServiceImpl getBuyerInfoByUserId end");
        return BaseResult.success(buyerInfo);
    }

    @Override
    public BaseResult getConsigneeList(String buyerId) {
        LOGGER.info("BuyserServiceImpl getConsigneeList begin");
        List<BuyerConsigneeVo> list = buyerInfoDao.getConsigneeList(buyerId);
        LOGGER.info("BuyserServiceImpl getConsigneeList end");
        return BaseResult.success(list);
    }

    @Override
    @Transactional
    public BaseResult saveConsigneeAddr(BuyerConsigneeVo buyerConsignee) {
        LOGGER.info("BuyserServiceImpl saveConsigneeAddr begin");

        LOGGER.info("BuyserServiceImpl saveConsigneeAddr checkParam begin");
        if (StringUtil.isEmpty(buyerConsignee.getBuyerId())) {
            return BaseResult.fail(ErrorCode.ParaCheckErrorRetCode,
                    ErrorCode.ParaCheckErrorRetInfo);
        }
        LOGGER.info("BuyserServiceImpl saveConsigneeAddr checkParam end");
        Integer i = null;
        try {
            i = buyerInfoDao.delConsiAddr(buyerConsignee.getBuyerId());
            LOGGER.info("BuyserServiceImpl saveConsigneeAddr addConsiAddr begin");
            buyerConsignee.setId(UUIDUtil.getUUID());
            buyerConsignee.setAddTime(new Date());
            buyerConsignee.setDelFlag("1");
            i = buyerInfoDao.addConsiAddr(buyerConsignee);
            LOGGER.info("BuyserServiceImpl saveConsigneeAddr addConsiAddr end");
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.info(ErrorCode.SQLExceptionRetInfo);
        }

        LOGGER.info("BuyserServiceImpl saveConsigneeAddr end");
        return BaseResult.success(i);
    }

    @Override
    public BaseResult updateSupportPayOnline(String userId) {
        Integer i = buyerInfoDao.updateSupportPayOnline(userId);
        if(null != i){
            return BaseResult.success("true");
        }
        return BaseResult.success("false");
    }

    @Override
    public BaseResult updateBuyerAuth(BuyerInfoVo buyerInfoVo) {
        int up = buyerInfoDao.updateBuyerAuth(buyerInfoVo);

        return BaseResult.success(up);
    }

}
